<div class="pageContent">
    <form method="post"
        action="${rc.getContextPath()}/manage/andonTemplate/saveOrUpdateAndonTemplate"
        class="pageForm required-validate"
        onsubmit="return validateCallback(this, dialogAjaxDone);">
        <div class="pageFormContent">
            <input type="hidden" name="navTabId" value="">
            <fieldset class="dataset">
                <dl>
                    <dt><@label key="andonTemplateCode.C,colon">ANDON模板编号：</@label></dt>
                    <dd>
                        <input name="templateCode"
                            value="<#if (andonTemplate.templateCode)??>${andonTemplate.templateCode!''}</#if>"
                            size="32" type="text" maxlength="20" class="required alphanumeric toUp"  readonly="true"
                        /> 
                    </dd>
                </dl>
                <dl>
                    <dt><@label key="desc.C,colon">描述：</@label></dt>
                    <dd>
                        <input name="templateText"
                            value="<#if (andonTemplate.templateText)??>${andonTemplate.templateText!''}</#if>"
                            size="32" type="text" maxlength="60" class="required"  readonly="true"
                        /> 
                    </dd>
                </dl>
                <dl>
                    <dt><@label key="andonType.C,colon">ANDON类型：</@label></dt>
                    <dd>
                        <select name="andonTypeCode" disabled="disabled">
                            <#if andonTemplate.andonTypeCode != ''>
                                <option value="${andonTemplate.andonTypeCode}" selected="selected">${andonTemplate.andonTypeText}</option>
                            <#else>
                                <option value="" selected="selected">所有</option>
                            </#if>
                        </select>
                    </dd>
                </dl>
                <dl>
                    <dt><@label key="andonMessageRule.C,colon">消息通知规则：</@label></dt>
                    <dd>
                        <input 
                            value="<#if (andonTemplate.ruleText)??>${andonTemplate.ruleText!''}</#if>"
                            size="32" type="text" class="  toUp textInput" readonly="readonly"
                        /> 
                        
                    </dd>
                </dl>
                 <dl>
                    <dt><@label key="event.C,colon">事件：</@label></dt>
                    <dd>
                        <input id="andonEventLookup.eventText"
                            value="<#if (andonTemplate.eventText)??>${andonTemplate.eventText!''}</#if>"
                            size="32" type="text" class="  toUp textInput" readonly="readonly"
                        /> 
                    </dd>
                </dl>
                <dl class="nowrap" >
                    <dt>&nbsp;</dt>
                    <dd>
                        <label  style="width:80px;">
                            <input name="alarmFlag" type="checkbox" disabled="disabled" value="1"  <#if (andonTemplate.alarmFlag)?? && 1==andonTemplate.alarmFlag>checked=true</#if> /> 
                            <@label key="alarm.C">报警</@label>
                        </label>
                         <label style="width:80px;">
                            <input name="lockFlag" type="checkbox" disabled="disabled" value="1"  <#if (andonTemplate.lockFlag)?? && 1==andonTemplate.lockFlag>checked=true</#if>/> 
                            <@label key="lock.C">锁定</@label>
                        </label>
                    </dd>
                </dl>
                <dl class="nowrap">
                        <div>
                            <#if andonTemplate??>
                            <#list andonTemplate.andonTemplateAttributeList as andonTemplateAttribute>
                                <input type='hidden' ref="${andonTemplateAttribute.attributeCode!''}"  value="${andonTemplateAttribute.attributeValue!''}"/>
                            </#list>
                            </#if>       
                             <div class="panel">
                                <h1><@label key="customAttribute.C">自定义属性</@label></h1>
                                <div class="panelContent">                 
		                            <table class="table border" style="width:100%;" layoutH="340">
		                               <thead>
		                                   <tr>
		                                       <th width="100"><@label key="name.C">名称</@label></th>
		                                       <th width="100"><@label key="Value.C">值</@label></th>
		                                   </tr>
		                               </thead>
		                               <tbody name="attributebody">
		                               </tbody>
		                              </table>
                                </div>
                            </div>
                        </div>
                </dl>
            </fieldset>
            <#if andonTemplate??>
                <#assign createInfo=andonTemplate>
                <#include "/common/createInfo.html">
            </#if>
            <div class="formBar">
            <ul>
                <li>
                    <div class="buttonActive" style="margin-left: 10px;">
                        <div class="buttonContent">
                            <button type="button" class="close"><@label
                                key="close.B">关闭</@label></button>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
        </div>
        
    </form>
</div>
<script type="text/javascript">
	(function($){
	    var page = DWZ.context();
	    //加载对应ANDON类型的自定义属性集合
	    function loadAndonAttributes(){
	    	var page = DWZ.context();
	    	$("tbody[name='attributebody']",page).html("");
	    	DWZ.ajax({
	            url : "${rc.getContextPath()}/manage/andonTemplate/listAndonAttributesByAndonType",
	            data : {andonType : $("select[name='andonTypeCode']",page).val()},
	            callback : function(json){
	            	if(json.data){
	            		var tbody = $("tbody[name='attributebody']",page);
	            		var trHtml = null ,elClass= null,andonAttribute = null,name=null, orgValue= null;
	            		for(var i = 0 ;i < json.data.length ; i++){
	            			andonAttribute = json.data[i];
	            			name = "andonTemplateAttributeList["+i+"].attributeCode";
	            			orgValue = $("input[type='hidden'][ref='"+andonAttribute["attributeCode"]+"']",page).length>0?$("input[type='hidden'][ref='"+andonAttribute["attributeCode"]+"']",page).val():'';
	            			
	            			elClass= "textInput valid";
	            			trHtml = "<tr><td>"+andonAttribute["attributeText"];
	            			trHtml = trHtml + "<input type='hidden' name='"+name+"' value='"+andonAttribute["attributeCode"]+"' />"+"</td>";
	            			
	            			if(1 === andonAttribute["requiredFlag"]){
	            				elClass = elClass+" required";
	            			}
	            			
	            			if("ENUM" === andonAttribute["valueTypeEcode"]){
	            				trHtml = trHtml + "<td><select name='"+name+"' class='"+elClass+"' disabled='disabled'>";
	            				if(andonAttribute["attributeEnumList"]){
	            					for(var j = 0 ; j < andonAttribute["attributeEnumList"].length ; j++){
	            						if(andonAttribute["attributeEnumList"][j]["attributeValue"] == orgValue){
	            							trHtml = trHtml + "<option value='"+andonAttribute["attributeEnumList"][j]["attributeValue"]+"' selected>"+andonAttribute["attributeEnumList"][j]["attributeValue"]+"</option>"
	            						}else{
	            							trHtml = trHtml + "<option value='"+andonAttribute["attributeEnumList"][j]["attributeValue"]+"'>"+andonAttribute["attributeEnumList"][j]["attributeValue"]+"</option>"	
	            						}
	            					}
	            				}
	            				trHtml = trHtml + "</select></td>";
	            			}else if("NUMBER" === andonAttribute["valueTypeEcode"]){
	                            	elClass = elClass + " digits";
	                            	trHtml = trHtml + "<td><input type='text' readonly='true' name='"+name+"' class='"+elClass+"' value='"+orgValue+"'/></td>"
	                        }else{
	                        	trHtml = trHtml + "<td><input type='text' readonly='true' name='"+name+"' class='"+elClass+"' value='"+orgValue+"'/></td>"
	                        }
	            			tbody.append(trHtml);
	            			
	            			
	            		}

	            		tbody.initUI();
	            	}
	            	
	            }
	        })
	    }
	    
	    loadAndonAttributes();
	    
	    $("select[name='andonTypeCode']",page).on("change",function(){
	    	loadAndonAttributes();
	    });
	    
	})(jQuery);
</script>